package com.yanqu.road.server.manger.maidian.hospitalroom;

import com.yanqu.road.entity.clinic.DepartmentData;
import com.yanqu.road.entity.clinic.DiseaseData;
import com.yanqu.road.entity.clinic.UserClinicData;
import com.yanqu.road.entity.config.clinic.DiseaseInfo;
import com.yanqu.road.entity.config.skill.SkillInfo;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.clinic.ClinicModule;
import com.yanqu.road.server.manger.DataAnalyticsMgr;
import com.yanqu.road.server.manger.config.ClinicMgr;
import com.yanqu.road.server.manger.config.SkillMgr;
import com.yanqu.road.server.manger.maidian.DefaultEventTraceAction;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class HospitalRoomLog {

    public static final String HOSPITAL_ROOM = "hospital_room";
    public static final String HOSPITAL_CONTENT = "hospital_content";
    public static final String HOSPITAL_PATIENT = "hospital_patient";
    public static final String HOSPITAL_CASE = "hospital_case";

    public static final String HOSPITAL_CONTENTNAME = "hospital_contentname";
    public static final String HOSPITAL_CONTENTLV = "hospital_contentlv";
    public static final String HOSPITAL_CASENAME = "hospital_casename";
    public static final String HOSPITAL_CASELV = "hospital_caselv";
    public static final String VOCATION = "vocation";
    public static final String HOSPITAL_CASEADD = "hospital_caseadd";


    public static void uploadSnapshot(GamePlayer player) {

        try {
            if (!DataAnalyticsMgr.openDataAnalytics()) return;

            DefaultEventTraceAction action = new DefaultEventTraceAction(HOSPITAL_ROOM, player);

            List<Map<String, Object>> objectGroup = new ArrayList<>();
            ClinicModule clinicModule = player.getModule(ClinicModule.class);
            UserClinicData userClinicData = clinicModule.getUserClinicData();
            for (Map.Entry<Integer, DepartmentData> departmentDataEntry : userClinicData.getDepartmentMap().entrySet()) {
                DepartmentData departmentData = departmentDataEntry.getValue();
                Map<String, Object> map = new HashMap<>();
                map.put(HOSPITAL_CONTENTNAME, departmentData.getType());
                map.put(HOSPITAL_CONTENTLV, departmentData.getLevel());
                objectGroup.add(map);
            }
            action.build(HOSPITAL_CONTENT, objectGroup);

            if(userClinicData.getUnLockPatientList().size() > 0) {
                int id = userClinicData.getUnLockPatientList().get(userClinicData.getUnLockPatientList().size() - 1);
                action.build(HOSPITAL_PATIENT, id);
            }

            //病症
            objectGroup = new ArrayList<>();
            for (Map.Entry<Integer, DiseaseData> diseaseDataEntry : userClinicData.getDiseaseDataMap().entrySet()) {
                DiseaseData diseaseData = diseaseDataEntry.getValue();

                Map<String, Object> map = new HashMap<>();
                map.put(HOSPITAL_CASENAME, diseaseData.getId());
                map.put(HOSPITAL_CASELV, diseaseData.getLevel());
                DiseaseInfo diseaseInfo = ClinicMgr.getDiseaseInfo(diseaseData.getId());
                if(diseaseInfo != null){
                    map.put(VOCATION, diseaseInfo.getOccupation());
                    SkillInfo skillInfo = SkillMgr.getSkillInfo(diseaseInfo.getSkill());
                    if (skillInfo != null) {
                        map.put(HOSPITAL_CASEADD, SkillMgr.getSkillAddition(skillInfo, diseaseData.getLevel()));
                    }
                }
                objectGroup.add(map);
            }
            action.build(HOSPITAL_CASE, objectGroup);

            action.trace();
        } catch (Exception e) {
            DataAnalyticsMgr.getLogger().error(" error ", e);
        }

    }


}
